#include "base.h"

class Solution
{
public:
    vector<int> sortedSquares(vector<int> &nums)
    {
        vector<int> v;
        v.resize(nums.size());
        int i = nums.size() - 1, l = 0, r = nums.size() - 1;
        while (r >= l)
        {
            long vl = nums[l];
            long vr = nums[r];
            if (vl * vl > vr * vr)
            {
                v[i] = vl * vl;
                l++;
            }
            else
            {
                v[i] = vr * vr;
                r--;
            }
            i--;
        }
        return v;
    }
};